/**
 * @file poj/1785/main
 * @brief
 * @see http://bailian.openjudge.cn/practice/solution/34585433/
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 5/28/2022 11:29:42
 **/

#include <algorithm>
#include <cstring>
#include <iostream>
#include <utility>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = 50005;
struct node {
  char s[100];
  int l, r, fa, idx;
  bool operator<(const node &rhs) const { return strcmp(s, rhs.s) < 0; }
} p[N];

void insert(int n) {
  for (int i = 1; i <= n; ++i) {
    int j = i - 1;
    while (p[j].idx < p[i].idx) j = p[j].fa;
    p[i].l = p[j].r;
    p[j].r = i;
    p[i].fa = j;
  }
}

void inorder(int x) {
  if (x == 0) return;
  putchar('(');
  inorder(p[x].l);
  printf("%s/%d", p[x].s, p[x].idx);
  inorder(p[x].r);
  putchar(')');
}

int main() {
  // High rating and good luck!
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  while (scanf("%d", &n) != EOF && n) {
    p[0].l = p[0].r = p[0].fa = 0;
    for (int i = 1; i <= n; ++i) {
      scanf(" %[^/]/%d", p[i].s, &p[i].idx);
      p[i].l = p[i].r = p[i].fa = 0;
    }
    p[0].idx = INF;
    sort(p + 1, p + 1 + n);
    insert(n);
    inorder(p[0].r);
    putchar('\n');
  }
  return 0;
}
